package com.itheima.loop;

public class ForDemo2 {
    public static void main(String[] args) {
        //用for循环批量生产数据
        for (int i = 1; i <= 100; i++) {
            System.out.println("i=" + i);
        }

        System.out.println("------------------");

        //定义一个变量，用来记录总和
        int sum = 0;
        for (int i = 1; i <= 100; i++) {
            sum += i;
        }
        System.out.println("总和=" + sum);

        System.out.println("------------------");

        int count = 0;
        //定义一个循环，用来打印100以内的奇数
        for (int i = 1; i <= 100; i += 2) {
            {
                count += i;
            }
        }
        System.out.println("100以内的奇数和=" + count);

        System.out.println("------------------");
        int count1 = 0;
        //定义一个for,if嵌套循环，用来打印100以内的偶数
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0){
                count1 += i;
            }
        }
        System.out.println("100以内的偶数和为" + count1);
    }
}
